clear;clc;
n = 2;
% A=rand(n, n);
B=rand(n, n);B=-100*(B*B');
C=rand(n, n);C=-100*(C*C');
% D=rand(n, n);
A=[1000 0;0 1140];
D=[1 0;0 2];
M=[A, -B;-C, D];


b = rand(2*n, 1);
x = M\b;

b1 = b(1:n,1);
b2 = b(n+1:end,1);
x1 = zeros(n, 1);
x2 = zeros(n, 1);
tp=zeros(10, 1);
tq=zeros(10, 1);
for i=1:10
    x1 = A\(b1+B*x2);
    x2 = D\(b2+C*x1);
    %disp(b-M*[x1;x2])
    p=max(max(abs(b-M*[x1;x2])));
    q=sum(sum(abs(b-M*[x1;x2])));
    err= norm(b-M*[x1;x2]);
    tp(i,1)=(err/p);
    tq(i,1)=(err/q);
    %tp(i,1)=(log10(err/p));
    %tq(i,1)=(log10(err/q));
    %t(i,1)=x1(1,1);t(i,2)=x1(2,1);
end